package com.jia.blog.controller;


import com.jia.blog.common.lang.R;
import com.jia.blog.entity.User;
import com.jia.blog.service.UserService;
import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.security.PublicKey;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jiajia
 * @since 2020-12-02
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户管理")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/info/{id}")
    public R info (@PathVariable Long id) {
        User user = userService.getById(id);
        return R.ok().data("data",user);
    }

    @PostMapping("/save")
    public R save(@RequestBody User user) {
        userService.save(user);
        return R.ok();
    }

    @PutMapping("/update")
    public R update(@RequestBody User user) {
        userService.updateById(user);
        return R.ok();
    }

    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable("id") Long id){
        userService.removeById(id);
        return R.ok();
    }



}
